$(document).ready(function() {
	document.addEventListener("alopexready", function() {
		init();
	});
});

/* title leftButton handler */
function backButtonHandler() {
	navigation.back();
}

/* title rightButton handler */
function homeButtonHandler() {
	navigation.goHome();
}

function _initHeader() {
	$("#titleBarBackButton").unbind("click");
	$("#titleBarHomeButton").unbind("click");
	$("#titleBarBackButton").click(backButtonHandler);
	$("#titleBarHomeButton").click(homeButtonHandler);
}

/*
 * draw list dynamically
 */
function draw_list(list) {
	var outputHtml = null;
	
	$.each(list, function(idx, value) {
		outputHtml = "";
		outputHtml += "<li id=\"btn_row_" + idx + "\"><a href=\"#\">" + value + "</a></li>";
		$("#listview").append(outputHtml);
		$("#btn_row_" + idx).click(function(e) {
			setOnListClickHandler(idx);
		});
	});
	
	$("#listview").listview("refresh");
}

/*
 * navigaion.navigate
 */
function navigate(pageId) {
	var navigationRule = {
		"pageId" : pageId
	};
	
	navigation.navigate(navigationRule);
}

function notifySuccess(functionName) {
	alert(functionName + " 수행 성공");
}

function notifyError(functionName, reason) {
	if(reason == null || reason == undefined)
		reason = "";
	
	alert(functionName + " 수행 실패 \n" + reason);
}

function commonProgress(message, cancelable, cancelCallback, color) {
	var option = {
		"message" : message,
		"cancelable" : cancelable,
		"cancelCallback" : cancelCallback,
		"color" : color
	};
	
	platformUIComponent.showProgressDialog(option);
}